package net.realsee.service.wcs.device.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.realsee.common.utils.StringUtils;
import net.realsee.domain.wcs.device.WcsVehicleStatus;
import net.realsee.domain.wcs.device.bo.WcsVehicleStatusBo;
import net.realsee.domain.wcs.device.vo.WcsVehicleStatusVo;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.mapper.wcs.device.WcsVehicleStatusMapper;
import net.realsee.service.wcs.device.IWcsVehicleStatusService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 车辆状态信息Service业务层处理
 *
 * @author realsee
 * @date 2023-08-11
 */
@RequiredArgsConstructor
@Service
public class WcsVehicleStatusServiceImpl extends ServiceImpl<WcsVehicleStatusMapper, WcsVehicleStatus> implements IWcsVehicleStatusService {

    private final WcsVehicleStatusMapper baseMapper;

    /**
     * 查询车辆状态信息
     */
    @Override
    public WcsVehicleStatusVo selectVoById(String status) {
        return baseMapper.selectVoById(status);
    }

    /**
     * 查询车辆状态信息列表
     */
    @Override
    public TableDataInfo<WcsVehicleStatusVo> selectVoPage(WcsVehicleStatusBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<WcsVehicleStatus> lqw = buildVoQueryWrapper(bo);
        Page<WcsVehicleStatusVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询车辆状态信息列表
     */
    @Override
    public List<WcsVehicleStatusVo> selectVoList(WcsVehicleStatusBo bo) {
        LambdaQueryWrapper<WcsVehicleStatus> lqw = buildVoQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<WcsVehicleStatus> buildVoQueryWrapper(WcsVehicleStatusBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<WcsVehicleStatus> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), WcsVehicleStatus::getStatus, bo.getStatus());
        lqw.like(StringUtils.isNotBlank(bo.getName()), WcsVehicleStatus::getName, bo.getName());
        lqw.eq(StringUtils.isNotBlank(bo.getFuid()), WcsVehicleStatus::getFuid, bo.getFuid());
        lqw.eq(bo.getTextId() != null, WcsVehicleStatus::getTextId, bo.getTextId());
        lqw.eq(bo.getRefrenceId() != null, WcsVehicleStatus::getRefrenceId, bo.getRefrenceId());
        lqw.eq(bo.getUnitId() != null, WcsVehicleStatus::getUnitId, bo.getUnitId());
        lqw.eq(bo.getDelFlag() != null, WcsVehicleStatus::getDelFlag, bo.getDelFlag());
        lqw.eq(StringUtils.isNotBlank(bo.getCreateBy()), WcsVehicleStatus::getCreateBy, bo.getCreateBy());
        lqw.eq(bo.getCreateTime() != null, WcsVehicleStatus::getCreateTime, bo.getCreateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getUpdateBy()), WcsVehicleStatus::getUpdateBy, bo.getUpdateBy());
        lqw.eq(bo.getUpdateTime() != null, WcsVehicleStatus::getUpdateTime, bo.getUpdateTime());
        lqw.eq(StringUtils.isNotBlank(bo.getDeleteBy()), WcsVehicleStatus::getDeleteBy, bo.getDeleteBy());
        lqw.eq(bo.getDeleteTime() != null, WcsVehicleStatus::getDeleteTime, bo.getDeleteTime());
        lqw.eq(bo.getRowVersionStamp() != null, WcsVehicleStatus::getRowVersionStamp, bo.getRowVersionStamp());
        return lqw;
    }

    /**
     * 新增车辆状态信息
     */
    @Override
    public Boolean insertByBo(WcsVehicleStatusBo bo) {
        WcsVehicleStatus add = BeanUtil.toBean(bo, WcsVehicleStatus.class);
        return this.save(add);
    }

    /**
     * 修改车辆状态信息
     */
    @Override
    public Boolean updateByBo(WcsVehicleStatusBo bo) {
        WcsVehicleStatus update = BeanUtil.toBean(bo, WcsVehicleStatus.class);
        return this.updateById(update);
    }

    /**
     * 批量删除车辆状态信息
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<String> ids) {
        return this.removeBatchByIds(ids);
    }

    @Override
    public List<WcsVehicleStatus> queryListNoPage() {
        return baseMapper.queryListNoPage();
    }
}
